<?php
class PurviewController extends CController {
	public function actionIndex() {
		$this->actionGroups ();
	}
	public function actionGroups() {
		$msg = "";
		$smarty = Yii::app ()->smarty;
		$groups = new Groups ( );
		if (isset ( $_POST ) && ! empty ( $_POST )) {
			$groups->title = addslashes ( $_POST ['title'] );
			if ($groups->save ()) {
				echo CommonFunc::AjaxCallbackMessage ( 'success',200,$groups->id );
				exit ();
			}
		}
		$ret = $groups->findAll ();
		$smarty->assign ( "msg", $msg );
		$smarty->assign ( "ret", $ret );
		$smarty->assign ( "body", "purview/groups" );
		$smarty->display ( "layouts.html" );
	}
	public function actionDel() {
		$data = addslashes ( $_POST ['data'] );
		$ids = explode ( ";", $data );
		foreach ( $ids as $id ) {
			if ($id) {
				$groups = new Groups ( );
				$groups->deleteByPk ( $id );
			}
		}
		echo CommonFunc::AjaxCallbackMessage ( 'success' );
		exit ();
	}
	public function actionEdit(){
		$title = addslashes ( $_POST ['title'] );
		$id = addslashes ( $_POST ['id'] );
		$groups = new Groups();
		$groups->updateByPk($id,array("title"=>$title));
		echo CommonFunc::AjaxCallbackMessage ( 'success' );
		exit ();
	}
	public function actionSet() {
		$msg = "";
		$admin = new Admin ( );
		$pur = new Purview ( );
		$smarty = Yii::app ()->smarty;
		if (isset ( $_POST ) && ! empty ( $_POST )) {
			$ret = array ();
			$passport = addslashes ( $_POST ['passport'] );
			foreach ( $_POST as $key => $v ) {
				$pos = strpos ( $key, "child" );
				if ($pos === FALSE) {
				} else {
					$ret [] = addslashes ( $v );
				}
			}
			$userpur = new UserPur ( );
			$userpur->deleteAll ( array (
				
				"condition" => "uid='$passport'" 
			) );
			foreach ( $ret as $v ) {
				$userpur = new UserPur ( );
				$userpur->setPur ( $passport, $v );
			}
		}
		$ret = $admin->getAdmin ();
		$lists = $pur->getPurview ();
		foreach ( $lists as $key => $v ) {
			$lists [$key] ['child'] = $pur->getPurByPid ( $v ['id'] );
		}
		
		$smarty->assign ( "lists", $lists );
		$smarty->assign ( "msg", $msg );
		$smarty->assign ( "ret", $ret );
		$smarty->assign ( "body", "purview/purviewset" );
		$smarty->display ( "layouts.html" );
	}
}
?>